package com.quasar.hpatient.module.mine;

import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.widget.ImageView;
import android.widget.TextView;

import com.quasar.hpatient.R;
import com.quasar.hpatient.dialog.QrcodeDialog;
import com.quasar.hpatient.module.comm_main.MainActivity;
import com.quasar.hpatient.module.comm_splash.SplashActivity;
import com.quasar.hpatient.module.mine_about.AboutActivity;
import com.quasar.hpatient.module.mine_favor.FavorActivity;
import com.quasar.hpatient.module.mine_file.MineFileActivity;
import com.quasar.hpatient.module.mine_info.MineInfoActivity;
import com.quasar.hpatient.module.mine_information.InformationActivity;
import com.quasar.hpatient.module.mine_pedometer.PedometerActivity;
import com.quasar.hpatient.module.mine_qrcode.MineQrcodeActivity;
import com.quasar.hpatient.module.mine_setting.MineSettingActivity;

import lib.quasar.base.frame.BaseFragment;
import lib.quasar.widget.menu.NavigationView;

/**
 * description: 我
 * created by kalu on 2018/4/2 11:03
 */
public final class MineFragment extends BaseFragment<MinePresenter> implements MineView {

    public final static int REQUEST_CODE = 1111;

    @Override
    public int initTheme() {
        return R.style.AppThemePeach;
    }

    @Override
    public int initView() {
        return R.layout.fragment_mine;
    }

    @Override
    public void initDataLocal() {

        final NavigationView menu = getView().findViewById(R.id.mine_menu);
        menu.setOnMenuChangeListener(() -> {
            Intent intent = new Intent(getContext(), MineSettingActivity.class);
            startActivityForResult(intent, REQUEST_CODE);
        });
        getView().findViewById(R.id.mine_icon).setOnClickListener(v -> goNext(InformationActivity.class));
        getView().findViewById(R.id.mine_qrcode).setOnClickListener(v -> goNext(MineQrcodeActivity.class));

        getView().findViewById(R.id.mine_menu1).setOnClickListener(v -> goNext(MineFileActivity.class));
        getView().findViewById(R.id.mine_menu3).setOnClickListener(v -> goNext(FavorActivity.class));
        getView().findViewById(R.id.mine_menu4).setOnClickListener(v -> goNext(PedometerActivity.class));
        getView().findViewById(R.id.mine_menu5).setOnClickListener(v -> goNext(AboutActivity.class));
        getView().findViewById(R.id.mine_icon).setOnClickListener(v -> goNext(MineInfoActivity.class));

        final TextView names = getView().findViewById(R.id.mine_name);
        final TextView phones = getView().findViewById(R.id.mine_phone);
        final ImageView images = getView().findViewById(R.id.mine_icon);
        getPresenter().loadInfo(this, names, phones, images);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode != REQUEST_CODE || resultCode != MineSettingActivity.RESULT_CODE) return;

        final FragmentActivity activity = getActivity();
        if (null == activity || !(activity instanceof MainActivity)) return;

        goNext(SplashActivity.class);
        MainActivity main = (MainActivity) activity;
        main.logout();
    }
}